function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}

/**
 * 
 * @param {number[]} nums 
 * @returns {ListNode | undefined} 
 */
function creatLink(nums) {
    // ans相当于保存的头指针
    // index相当于前进指针
    let ans = null;
    let index = null;
    for (let i = 0; i < nums.length; i++) {
        if (i < 1) {
            ans = new ListNode(nums[i]);
            index = ans;
        } else {
            index.next = new ListNode(nums[i]);
            index = index.next;
        }
    }
    // console.log(JSON.stringify(ans))
    return ans;
}

module.exports = creatLink;